package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.vo.SkuDetailVo;
import com.atguigu.gmall.weball.feign.SkuDetailFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class ItemController {
    @Autowired
    SkuDetailFeignClient skuDetailFeignClient;
    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId, Model model){



        //远程调用商品详情服务返回数据
        Result<SkuDetailVo> skuDetail = skuDetailFeignClient.getSkuDetail(skuId);
        SkuDetailVo skuDetailVo = skuDetail.getData();



        //当前商品所属的详细分类数据
        model.addAttribute("categoryView",skuDetailVo.getCategoryView());

        //id,skuname，skuDefaultImg，skuImageList[]，weight
        model.addAttribute("skuInfo",skuDetailVo.getSkuInfo());

        //spuSaleAttrList 拿到当前sku所属的spu当时到底定义了多少搁销售属性名和值
        model.addAttribute("spuSaleAttrList",skuDetailVo.getSpuSaleAttrList());

        //valuesSkuJson json字符串
        model.addAttribute("valuesSkuJson",skuDetailVo.getValuesSkuJson());

        //在详情页显示价格
        model.addAttribute("price",skuDetailVo.getSkuPrice());

        return "item/index";
    }
}
